function rand(min, max) {
    return min + Math.round(Math.random() * (max - min));
}
export function typing(targetString, write, minTime = 50, maxTime = 500) {
    return new Promise((resolve) => {
        let currentIndex = 0;
        const next = async () => {
            targetString += "";
            if (currentIndex < targetString.length) {
                await write(targetString[currentIndex]);
                currentIndex++;
                setTimeout(next.bind(this), // 递归自身，并传参
                rand(minTime, maxTime));
            }
            else {
                if (resolve)
                    resolve(true); // 所有字符自增完成
            }
        };
        next();
    });
}
